package com.w.tank;

import java.awt.*;

public class Bullet extends GameObject{
    private static final int speed = 20;
    private Dir dir;
    static int WIDTH = ResourceMgr.bulletD.getWidth(), HEIGHT=ResourceMgr.bulletD.getHeight();

    public Group getGroup() {
        return group;
    }

    private Group group = Group.GOOD;


    Rectangle rect = new Rectangle();


    public Bullet(int x, int y, Dir dir, Group group){
        this.x = x;
        this.y = y;
        this.dir = dir;
        this.group = group;
        rect.width = WIDTH;
        rect.height = HEIGHT;
        GameControl.getInstance().add(this);

    }

    public void paint(Graphics g){

        if(!isLive()){
            GameControl.getInstance().remove(this);

        }
        switch (dir){
            case UP:
                g.drawImage(ResourceMgr.bulletU, x, y, null);
                break;
            case DOWN:
                g.drawImage(ResourceMgr.bulletD, x, y, null);
                break;
            case LEFT:
                g.drawImage(ResourceMgr.bulletL, x, y, null);
                break;
            case RIGHT:
                g.drawImage(ResourceMgr.bulletR,x, y,null);
        }
        move();

    }

    @Override
    public int getWidth() {
        return WIDTH;
    }

    @Override
    public int getHeight() {
        return HEIGHT;
    }

    private void move() {

        switch (dir){
            case UP:
                y -= speed;
                break;
            case DOWN:
                y += speed;
                break;
            case LEFT:
                x -= speed;
                break;
            case RIGHT:
                x += speed;
                break;
            default:
                break;
        }
        if (x<0||y<0||x> TankFrame.GAME_WIDTH||y > TankFrame.GAMT_HEIGHT)live = false;
        rect.x = x;
        rect.y = y;


    }



}
